// pages/student/student.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    staticUrl: '',
    apiUrl: '',
    date: '请选择时间',
    user:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      staticUrl: app.globalData.staticUrl,
      apiUrl: app.globalData.apiUrl
    })
    var myDate = new Date();
    var year = myDate.getFullYear();
    var month = myDate.getMonth() + 1;
    var day = myDate.getDate();
    if (month > 9) {
      this.setData({
        date: year + '-' + month + '-' + day
      })
    } else {
      this.setData({
        date: year + '-0' + month + '-' + day
      })
    }
    this.getstuden();
  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
    this.getstuden();

  },
  getstuden:function(){
    // 发起网络请求
    var userinfo = wx.getStorageSync("userInfo");
    wx.request({
      url: this.data.apiUrl + '/coach/mystudent.do',
      data: {
        status: userinfo.status,
        session_key: wx.getStorageSync("session_key"),
        openid: wx.getStorageSync("openid"),
        cid: userinfo.cid,
        date: this.data.date
      },
      method: 'GET',
      success: (res) => {
        console.log(res, '获取工单')
        this.setData({
          user: res.data.appointments
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})